package com.cloud.test.usercustomerhy.controller;

import com.cloud.test.usercustomerhy.pojo.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author HanLiBin
 * @version V1.0
 */
@RestController
public class UserController {
    @Autowired
    private RestTemplate template;

    @GetMapping("/movice/{id}")
    @HystrixCommand(fallbackMethod = "fallbackgetUser",commandProperties = @HystrixProperty(name = "execution.isolation.strategy",value = "SEMAPHORE"))
    public User findOneById(@PathVariable Integer id) {
        return template.getForObject("http://localhost:7911/simple/" + id, User.class);
    }

//    @Autowired
//    private UserFeign userFeign;
//
//    @GetMapping("/movice/{id}")
//    public User getUser(@PathVariable Integer id){
//       return userFeign.getUser(id);
//    }
    public User fallbackgetUser(Integer id){
        return  new User();
    }
}
